package com.gking.centerSystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gking.centerSystem.entity.Roles;
import com.gking.centerSystem.entity.Routes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RolesMapper extends BaseMapper<Roles> {

    /**
     * 获取角色列表
     *
     * @param page      分页信息
     * @param sortIds   分类id列表
     * @param isDefault 是否默认
     * @param realName  角色名称
     * @return
     */
    @Select("<script>" +
            "SELECT DISTINCT roles.* " +
            "FROM sy_roles roles " +
            "JOIN sy_sort sort ON sort.id = roles.sortId " +
            "JOIN sy_root_system rootSystem ON rootSystem.systemCode = sort.systemCode " +
            "WHERE rootSystem.enable = 0 AND rootSystem.isDelete = 0 " +
            "AND sort.isDelete = 0 AND roles.isDelete = 0 " +

            "<if test='sortIds != null and !sortIds.isEmpty()'>" +
            " AND roles.sortId IN " +
            " <foreach item='sortId' index='index' collection='sortIds' open='(' separator=',' close=')'>" +
            "   #{sortId}" +
            " </foreach>" +
            "</if> " +

            "<if test='isDefault != null'> AND roles.isDefault = #{isDefault} </if> " +
            "<if test='realName != null and realName.trim() neq \"\" '>" +
            " AND roles.realName LIKE CONCAT('%', #{realName}, '%') " +
            "</if>" +

            "ORDER BY roles.createTime DESC  " +
            "</script>")
    Page<Roles> getRolesList(Page<Roles> page,
                             @Param("sortIds") List<String> sortIds,
                             @Param("isDefault") Integer isDefault,
                             @Param("realName") String realName);

}
